<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>订单表</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css?t=1615206508080" media="all">
    <script src="../../res/js/jquery.js"></script>
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>
<div class="list_main">

    <div class="list_query">
        <form id="queryForm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">运单编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="waybillId" id="waybillId" autocomplete="off" placeholder="请输入运单编号"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">运单状态</label>
                    <div class="layui-input-inline">
                        <input type="text" name="waybillState" id="waybillState" autocomplete="off" placeholder="请输入运单状态"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出发地</label>
                    <div class="layui-input-inline">
                        <input type="text" name="waybillDeparture" id="waybillDeparture" autocomplete="off" placeholder="请输入出发地"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">目的地</label>
                    <div class="layui-input-inline">
                        <input type="text" name="waybillBourn" id="waybillBourn" autocomplete="off" placeholder="目的地"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">

                    <div class="layui-input-inline">
                        <input type="button" class="layui-btn" value="查询" id="query_btn">
                    </div>
                </div>
            </div>
        </form>
    </div>

    <table class="layui-hide" id="demo" lay-filter="test"></table>

</div>

<!-- 监听头工具栏 -->
<!--<script type="text/html" id="toolbarDemo">-->
<!--    <div class="layui-btn-container">-->
<!--        <button class="layui-btn layui-btn-sm" lay-event="add">增加</button>-->
<!--        <button class="layui-btn  layui-btn-danger  layui-btn-sm" lay-event="delete">删除</button>-->
<!--    </div>-->
<!--</script>-->
<script type="text/html" id="barDemo">
    <!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="../../res/layui/layui.js?t=1615206508080"></script>
<script>
    var table;
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
            ,layer = layui.layer //弹层

            ,carousel = layui.carousel //轮播
            ,upload = layui.upload //上传
            ,element = layui.element //元素操作
            ,slider = layui.slider; //滑块
        table = layui.table //表格
        //执行一个 table 实例
        table.render({
            elem: '#demo'
            ,id:'logisticsWaybillTable'
            ,height: 650
            ,url: '/logisticsWaybill/select' //数据接口
            ,title: '订单表'
            ,page: true //开启分页
            // ,toolbar: '#toolbarDemo' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            // , totalRow: true //开启合计行
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'waybillId', title: '运单ID', width:190, sort: true, fixed: 'left', totalRowText: '合计：'}
                // ,{field: 'staffId', title: '员工ID', width:80}
                // ,{field: 'clientId', title: '寄件人ID', width: 90, sort: true, totalRow: true}
                // ,{field: 'cargoId', title: '货物ID', width:80, sort: true}

                ,{field: 'carId', title: '车辆ID', width:90}
                ,{field: 'waybillState', title: '运单状态', width: 120}
                ,{field: 'waybillStartTime', title: '出发时间', width: 110}
                ,{field: 'waybillGetTime', title: '到达时间', width:190, sort: true, totalRow: true}
                ,{field: 'waybillDeparture', title: '出发地', width: 100}
                ,{field: 'waybillBourn', title: '目的地', width: 100}
                // ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    layer.msg('添加');
                    break;
                case 'update':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
                    }
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.msg('删除');
                    }
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
                layer.msg('查看操作');
            } else if(layEvent === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){
                layer.msg('编辑操作');
            }
        });
    });

    $(function () {
        $("#query_btn").on("click", function () {
            //执行查询
            var data_ = {
                waybillId: $("#waybillId").val(),
                waybillState: $("#waybillState").val(),
                waybillDeparture: $("#waybillDeparture").val(),
                waybillBourn:$("#waybillBourn").val()
            };
            //执行重载
            table.reload('logisticsWaybillTable', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: data_ //需要传到后台的参数
            });

        })
    })


</script>
</body>
</html>
